﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FJASPX.Service;
using NHibernate.Criterion;
using FJASPX.Framwork.Helper;
using FJASPX.Framwork.Constant;
namespace PlugNT.Cms.Web.Home
{
    public partial class Show : System.Web.UI.Page
    {
        public string Logo { get; set; }
        public IProductService iProductService { get; set; }

        public IProductClassService iProductClassService { get; set; }

        public IUserService iUserService { get; set; }

        public FJASPX.Domain.User user;

        public FJASPX.Domain.Product product;

        public IEnterpriseService iEnterpriseService { get; set; }

        public FJASPX.Domain.Enterprise enterprise;
        private void Filter()
        {
            if (Request.QueryString["User"].IsNull())
            {
                Response.Redirect(Strings.PAGE_ERROR);
            }
            try
            {
                user = iUserService.Get(Request.QueryString["User"].ToInt());
                if (user == null)
                {
                    Response.Redirect(Strings.PAGE_ERROR);
                }
                enterprise = iEnterpriseService.GetByUser(user);
                if (enterprise == null)
                {
                    enterprise = new FJASPX.Domain.Enterprise();
                    enterprise.Name = user.CompanyName;
                    enterprise.Contant = user.RealName;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Filter();

            if (String.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                Response.Redirect("/index.shtml");
            }

            product = iProductService.Get(Int32.Parse(Request.QueryString["Id"]));
            if (product == null)
            {
                Response.Redirect("/index.shtml");
            }

        }
        public IList<FJASPX.Domain.ProductClass> getProductClass()
        {
            long totalCount = 0;
            ICriterion criterion = null;// Expression.Eq("UserName", Request.QueryString["User"]);
            List<Order> orders = new List<Order>();
            orders.Add(new Order("TimeStamp", false));
            return iProductClassService.PagedQuery(criterion, orders, 0, 20, out totalCount);
        }

        public string GetClassName(int classId)
        {
            FJASPX.Domain.ProductClass productClass = iProductClassService.Get(classId);
            if (product != null)
            {
                return product.Name;
            }
            return "未知类别";
        }
    }
}